package com.andy.blog.admin.controller;

import com.andy.blog.admin.dto.TagDTO;
import com.andy.blog.admin.service.TagBusService;
import com.andy.blog.common.annotation.Log;
import com.andy.blog.common.enums.BusinessTypeEnum;
import com.andy.blog.common.page.PageUtilsDTO;
import com.andy.blog.common.reponse.GeneralResponseResult;
import com.andy.blog.dal.vo.TagVO;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by andy on 2023/6/18 17:11
 */
@RestController
public class TagController {

    @Resource
    private TagBusService tagBusService;

    /**
     * 根据条件分页查询
     */
    //@PreAuthorize("@ss.hasPermi('system:dict:list')")
    @GetMapping("/article/tag/selectListByPage")
    public GeneralResponseResult<PageUtilsDTO<TagDTO>> selectListByPage(TagVO tagVO) {
        return GeneralResponseResult.success(tagBusService.selectListByPage(tagVO));
    }

    /**
     * 条件查询
     */
    @GetMapping("/article/tag/selectList")
    public GeneralResponseResult<List<TagDTO>> selectList(TagVO tagVO) {
        return GeneralResponseResult.success(tagBusService.selectList(tagVO));
    }

    /**
     * 新增
     */
    @Log(title = "标签管理", businessType = BusinessTypeEnum.INSERT)
    @PostMapping("/article/tag/addTag")
    public GeneralResponseResult<Void> addTag(@Validated @RequestBody TagVO tagVO) {
        tagBusService.addTag(tagVO);
        return GeneralResponseResult.success();
    }

    /**
     * 查询标签详细
     */
    //@PreAuthorize("@ss.hasPermi('system:dict:query')")
    @GetMapping(value = "/article/tag/{tagId}")
    public GeneralResponseResult<TagDTO> getById(@PathVariable Long tagId) {
        return GeneralResponseResult.success(tagBusService.selectTagById(tagId));
    }

    /**
     * 修改标签
     */
    //@PreAuthorize("@ss.hasPermi('system:dept:edit')")
    @Log(title = "标签管理", businessType = BusinessTypeEnum.UPDATE)
    @PutMapping("/article/tag")
    public GeneralResponseResult<Void> updateTag(@Validated @RequestBody TagVO tagVO) {
        tagBusService.updateTag(tagVO);
        return GeneralResponseResult.success();
    }

    @GetMapping("/portal/tag/list")
    public GeneralResponseResult<List<TagDTO>> listTagVO() {
        return GeneralResponseResult.success(tagBusService.listTagVO());
    }
}
